﻿using Ekton_Manage_DomainCore.Aggregate;
using Ekton_Manage_DTO.RequestModels.User;
using Ekton_Manage_IBusiness;
using Ekton_Manage_InfrastructureCore.Common;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System;
using System.Threading.Tasks;

namespace Ekton_Manage_Web.Controllers
{
         /// <summary>
        /// 公司组织
        /// </summary>
        /// 
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize("Permission")]
    public class OrganizeController : ControllerBase
    {
       
        private readonly ICompany _company;

        public OrganizeController(ICompany company)
        {
             _company = company;
        }

        /// <summary>
        /// 查询全部组织管理
        /// </summary>
        /// 
        [HttpGet]
        public async Task<MessageModel<PageModel<company>>> GetOrganizeList([FromQuery] QueryDataParame query)
        {
            var result = await _company.GetCompany(query);

            return new MessageModel<PageModel<company>>
            {
                msg = "数据获取成功",
                response = new PageModel<company>
                {
                    pageIndex = query.pageIndex,
                    pageCount = Convert.ToInt32(Math.Ceiling(Convert.ToDecimal(result.Item2) / query.pageSize)),
                    dataCount = result.Item2,
                    pageSize = query.pageSize,
                    data = result.Item1
                }
            };
        }

        /// <summary>
        /// 编辑组织管理
        /// </summary>
        /// 
        [HttpPut]
        public async Task<Message> PutOrganizeInfo([FromBody] DtoInsertCompany query)
        {
            return await _company.PutCompany(query);
        }

        /// <summary>
        /// 添加组织管理
        /// </summary>
        /// 
        [HttpPost]
        public async Task<Message> PostOrganizeInfo([FromBody] DtoInsertCompany query)
        {
            return await _company.PostCompany(query);
        }

        /// <summary>
        /// 删除组织管理
        /// </summary>
        /// 
        [HttpDelete]
        public async Task<Message> DeleteOrganizeInfo(int id)
        {
            return await _company.DeleteOrganizeInfo(id);
        }
    }
}
